package com.qingke.pms.command.user;

import com.qingke.pms.command.UserCommand;
import com.qingke.pms.pojo.Material;
import com.qingke.pms.pojo.User;
import com.qingke.pms.util.PMSConsole;

public class AddMaterialCommand extends UserCommand {

	public AddMaterialCommand(User user) {
		super(user);
	}

	@Override
	public void execute() {
		Material material=new Material();
		String code;
		while(true){
			code=PMSConsole.promptNotEmpty("code:");
			if(dao.isMaterialExistByCode(code)){
				PMSConsole.println("the code have been existed.");
				continue;
			}
			break; 
		}
		String name=PMSConsole.promptNotEmpty("name:");
		String model=PMSConsole.promptNotEmpty("model:");
		String unit=PMSConsole.promptNotEmpty("unit:");
		
		material.setCode(code);
		material.setName(name);
		material.setModel(model);
		material.setUnit(unit);
		
		boolean isSuccess=dao.insertMaterial(material);
		if(isSuccess)
			PMSConsole.println("add material success.");
		else
			PMSConsole.println("add material failed.");
	}

}
